/**
 * 
 */
package dao.versant;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

import javax.jdo.Query;

import dao.interfaces.ITrainDAO;

import tp.model.Client;
import tp.model.Train;

/**
 * @author Admin
 *
 */
public class TrainDAOVersant extends VersantDAO<Train> implements ITrainDAO {

	@Override
	public Train find(String nomTrain) {
		Query q = pm.newQuery(Train.class);
		q.declareParameters("String train");
		q.setFilter("nom == train");
		Train train = null;
		Collection collection;
		try {
			collection = (Collection) q.execute(nomTrain);
			if (!collection.isEmpty()) {
				Iterator i = collection.iterator();
				if (i.hasNext())
					train = (Train) i.next();
			}
		} finally {
			if (train != null) q.close(train);
		}
		return train;
	}
	
	@Override
	public void create(Train train) {
		pm.currentTransaction().begin();
		pm.makePersistent(train);
		pm.currentTransaction().commit();
	}
	
	@Override
	public ArrayList<Train> findAll() {
		return null;
	}

	@Override
	public void delete(Train obj) {
		
	}

}
